package com.conver;

import com.zjs.exception.NoPermissionException;
import org.springframework.web.servlet.HandlerExceptionResolver;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * @类名： ExportExceptionResolver
 * @说明： TODO
 * @作者：SS 苏帅出品
 * @时间：2019/12/15 23:01
 * @版本：1.0
 */
public class ExportExceptionResolver implements HandlerExceptionResolver {
    @Override
    public ModelAndView resolveException(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, Object o, Exception e) {
        NoPermissionException noPermissionException=null;


        if (e instanceof NoPermissionException){

            noPermissionException= (NoPermissionException) e;


        }else{

            noPermissionException=new NoPermissionException(e.getMessage());

        }

        ModelAndView modelAndView=new ModelAndView("unauthorize");


        modelAndView.addObject("error",noPermissionException.getMes());

        return modelAndView;
    }
}
